<template>
  <div>
    <div class="pad-20">
      <el-table :data="taskLogList" @sort-change="sortChange" @selection-change="handleSelectionChange"
                v-loading="listLoading" element-loading-text="加载中"
                style="width: 100%">
        <el-table-column label="时间" prop="createTime">
        </el-table-column>
        <el-table-column label="日志信息" prop="content">
        </el-table-column>
        <el-table-column label="操作者" prop="createUserName">
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <div class="pagination">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                      :current-page="taskLogListQuery.currentPage"
                      :page-sizes="[10, 20, 50, 100]" :page-size="taskLogListQuery.size"
                      layout="total, sizes, prev, pager, next, jumper"
                      :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<style scoped>

</style>

<script>
  import { pageTaskLog } from '@/api/project/taskLog'
  export default {
    props: {
      taskId: {
        type: String
      },
      positionId: {
        type: String
      }
    },
    data() {
      return {
        taskLogList: [],
        total: null,
        listLoading: true,
        multipleSelection: [],
        taskLogListQuery: {
          currentPage: 1,
          size: 10,
          taskId: this.taskId,
          positionId: this.positionId
        },
        taskLog: {
          taskLogId: '',
          taskId: '',
          positionId: '',
          createUserId: '',
          createUserName: '',
          content: '',
          createTime: '',
          enterpriseId: ''
        }
      }
    },
    // 过滤器
    filters: {
      statusFilter(status) {
        const statusMap = {
          1: 'success',
          2: 'danger'
        }
        return statusMap[status]
      }
    },
    // 初始化页面
    created() {
      this.initTaskLogList()
    },
    methods: {
      initTaskLogList() {
        this.listLoading = true
        pageTaskLog(this.taskLogListQuery).then(response => {
          this.taskLogList = response.records
          this.total = response.total
          this.listLoading = false
        })
      },
      // 列表排序
      sortChange(data) {
        const { prop, order } = data
        if (prop === 'createTime') {
          if (order === 'ascending') {
            this.taskLogListQuery.ascs = 'createTime'
            this.taskLogListQuery.descs = ''
          } else {
            this.taskLogListQuery.ascs = ''
            this.taskLogListQuery.descs = 'createTime'
          }
        }
        this.initTaskLogList()
      },
      handleSearch() {
        this.taskLogListQuery.currentPage = 1
        this.initTaskLogList()
      },
      handleSizeChange(val) {
        this.taskLogListQuery.size = val
        this.initTaskLogList()
      },
      handleCurrentChange(val) {
        this.taskLogListQuery.currentPage = val
        this.initTaskLogList()
      },
      handleSelectionChange(val) {
        this.multipleSelection = val
      }
    },
    mounted() {
    }
  }
</script>
